package com.atguigu.orderService.service.impl;

import com.atguigu.commonUtils.vo.CourseVo;
import com.atguigu.commonUtils.vo.UcenterMemberVo;
import com.atguigu.orderService.client.EduClient;
import com.atguigu.orderService.client.UcenterClient;
import com.atguigu.orderService.entity.Order;
import com.atguigu.orderService.mapper.OrderMapper;
import com.atguigu.orderService.service.OrderService;
import com.atguigu.orderService.utils.OrderNoUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author Chen Wen bo
 * @since 2021-08-20
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Resource
    private EduClient eduClient;
    @Resource
    private UcenterClient ucenterClient;

    //生成订单
    @Override
    public String createOrder(String courseId, String id) {
        //通过远程调用获取用户信息
        UcenterMemberVo member = ucenterClient.getMember(id);
        //通过远程调用获取课程信息
        CourseVo courseInfo = eduClient.getCourseInfo(courseId);
        Order order = new Order();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseInfo.getTitle());
        order.setCourseCover(courseInfo.getCover());
        order.setTeacherName(courseInfo.getTeacherName());
        order.setTotalFee(courseInfo.getPrice());
        order.setMemberId(id);
        order.setMobile(member.getMobile());
        order.setNickname(member.getNickname());
        order.setStatus(0);
        order.setPayType(1);
        baseMapper.insert(order);
        return order.getOrderNo();
    }
}
